//
//  TMMenuControl.m
//  TMGold
//
//  Created by Mac on 2017/12/8.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMMenuControl.h"
@interface TMMenuControl()
@property(nonatomic, strong) NSString                     *originTextStr;
@end
@implementation TMMenuControl

- (instancetype)initWithFrame:(CGRect)frame value:(NSString *)value name:(NSString *)name showLine:(BOOL)showLine{
    if (self == [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.valueLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 8, self.st_width, 19)
                                                    text:[NSString stringWithFormat:@"%@克",value]
                                               textColor:TM_firstTextColor
                                                    font:15
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
        self.valueLable.st_centerX = self.st_width / 2;
        self.originTextStr = value;
        [self addSubview:self.valueLable];
        self.valueLable.attributedText = [self.valueLable.text st_convertAttributeStringWithKeyWord:@"克" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}];
        self.nameLable = [[STLabel alloc] initWithFrame:CGRectMake(0, self.valueLable.st_bottom + 10,self.st_width, 13)
                                                   text:name
                                              textColor:TM_secendTextColor
                                                   font:13
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentCenter];
        self.nameLable.st_centerX = self.st_width / 2;;
        [self addSubview:self.nameLable];
        self.lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 0.6 * self.st_height)];
        self.lineView.backgroundColor = TM_lineColor;
        self.lineView.st_centerY = self.st_height /2;
        self.lineView.st_right = self.st_width - 1;
        [self addSubview:self.lineView];
        self.lineView.hidden = !showLine;
        self.clipsToBounds = YES;
        
    }
    return self;
}
- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
        self.valueLable.text = [NSString stringWithFormat:@"%@克",self.originTextStr];
        self.valueLable.attributedText = [self.valueLable.text st_convertAttributeStringWithKeyWord:@"克" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}];
    }else{
        self.valueLable.text = [NSString stringWithFormat:@"%@克",@"****"];
        self.valueLable.attributedText = [self.valueLable.text st_convertAttributeStringWithKeyWord:@"克" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}];
    }
}
@end
